package com.obas.command {
    import com.ease.util.events.MethodReturnEvent;
    import com.ease.framework.ViewRegistry;
    import com.ease.flex.remoting.ServiceManagerComObasTestingFlexRemoting;
    import com.obas.event.ItestOperationEvent;
    import com.obas.event.ParameterPoolEvent;
    import com.obas.event.RequestExplorerEvent;
    import com.obas.event.ScriptOperationEvent;
    import com.obas.event.TestPlanOperationEvent;
	
    import flash.events.EventDispatcher;
	import com.ease.common.vo.Pagination;
	import com.ease.common.vo.Ordering;

   [Event(name="{com.obas.event.ItestOperationEvent.RETURN_ID}", type="com.obas.event.ItestOperationEvent")]
   [Event(name="{com.obas.event.ScriptOperationEvent.RETURN_ID}", type="com.obas.event.ScriptOperationEvent")]
   [Event(name="{com.obas.event.RequestExplorerEvent.RETURN_ID}", type="com.obas.event.RequestExplorerEvent")]
   [Event(name="{com.obas.event.ParameterPoolEvent.RETURN_ID}", type="com.obas.event.ParameterPoolEvent")]
   [Event(name="{com.obas.event.TestPlanOperationEvent.RETURN_ID}", type="com.obas.event.TestPlanOperationEvent")]
   
   
   public class TestingLibCommand extends EventDispatcher {	   
	   
	 
	   
       [RequestHandler("{com.obas.event.ItestOperationEvent.REQUEST_ID}")]
       public static function onPItestOperationEvent(request:ItestOperationEvent):void {
           var requestParam:Object = request.spec as Object;
           switch(request.actionType) {
              case ItestOperationEvent.GET_PROJECT:
                 ServiceManagerComObasTestingFlexRemoting.getSystemProjectAccessService().findAll(null, onOperationReturn, request);
                 break;
              case ItestOperationEvent.GET_SCENARIO:
                 ServiceManagerComObasTestingFlexRemoting.getSystemScenarioAccessService().findBySystemProjectId(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.GET_CASE:
                 ServiceManagerComObasTestingFlexRemoting.getSystemUsecaseAccessService().findBySystemScenarioId(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.GET_FUNCTION:
                 ServiceManagerComObasTestingFlexRemoting.getSystemFunctionAccessService().findBySystemUsecaseId(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.GET_SCRIPT:
                 ServiceManagerComObasTestingFlexRemoting.getTestcaseScriptAccessService().findBySystemFunctionId(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.ADD_PROJECT:
                 ServiceManagerComObasTestingFlexRemoting.getSystemProjectAccessService().save(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.ADD_SCENARIO:
                 ServiceManagerComObasTestingFlexRemoting.getSystemScenarioAccessService().createEntity(request.spec[0], request.spec[1], onOperationReturn, request);
                 break;
              case ItestOperationEvent.UPDATE_SCENARIO:
                 ServiceManagerComObasTestingFlexRemoting.getSystemScenarioAccessService().update(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.ADD_USECASE:
                 ServiceManagerComObasTestingFlexRemoting..getSystemUsecaseAccessService().createEntity(request.spec[0], request.spec[1], onOperationReturn, request);
                 break;
              case ItestOperationEvent.UPDATE_USECASE:
                 ServiceManagerComObasTestingFlexRemoting.getSystemUsecaseAccessService().update(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.ADD_USECASE_WITH_BUSINESSUSECASE:
                 ServiceManagerComObasTestingFlexRemoting.getSystemUsecaseAccessService().createEntityWithBusinessUsecase(request.spec[0], request.spec[1], request.spec[2], onOperationReturn, request);
                 break;
              case ItestOperationEvent.ADD_FUNCTION:
                 ServiceManagerComObasTestingFlexRemoting.getSystemFunctionAccessService().createEntity(request.spec[0], request.spec[1], onOperationReturn, request);
                 break;
              case ItestOperationEvent.UPDATE_FUNCTION:
                 ServiceManagerComObasTestingFlexRemoting.getSystemFunctionAccessService().update(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.ADD_SCRIPT:
                 ServiceManagerComObasTestingFlexRemoting.getTestcaseScriptAccessService().createEntity(request.spec[0], request.spec[1], onOperationReturn, request);
                 break;
              case ItestOperationEvent.DELETE_CASE:
                 ServiceManagerComObasTestingFlexRemoting.getSystemUsecaseAccessService().remove(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.DELETE_FUNCTION:
                 ServiceManagerComObasTestingFlexRemoting.getSystemFunctionAccessService().remove(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.DELETE_PROJECT:
                 ServiceManagerComObasTestingFlexRemoting.getSystemProjectAccessService().remove(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.DELETE_SCENARIO:
                 ServiceManagerComObasTestingFlexRemoting.getSystemScenarioAccessService().remove(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.DELETE_SCRIPT:
                 ServiceManagerComObasTestingFlexRemoting.getTestcaseScriptAccessService().remove(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.UPDATE_PROJECT:
                 ServiceManagerComObasTestingFlexRemoting.getSystemProjectAccessService().update(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.ADD_BUSINESSREPOSITORY:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessRepositoryAccessService().save(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.ADD_BUSINESSSCENARIO:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessScenarioAccessService().createEntity(request.spec[0], request.spec[1], onOperationReturn, request);
                 break;
              case ItestOperationEvent.ADD_BUSINESSUSECASE:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessUsecaseAccessService().createEntity(request.spec[0], request.spec[1], onOperationReturn, request);
                 break;
              case ItestOperationEvent.ADD_BUSINESSFUNCTION:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessFunctionAccessService().createEntity(request.spec[0], request.spec[1], onOperationReturn, request);
                 break;
              case ItestOperationEvent.GET_BUSINESSREPOSITORY:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessRepositoryAccessService().findAll(null, onOperationReturn, request);
                 break;
              case ItestOperationEvent.GET_BUSINESSSCENARIO:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessScenarioAccessService().findByBusinessRepositoryId(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.GET_BUSINESSUSECASE:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessUsecaseAccessService().findByBusinessScenarioId(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.GET_BUSINESSFUNCTION:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessFunctionAccessService().findByBusinessUsecaseId(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.DELETE_BUSINESSREPOSITORY:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessRepositoryAccessService().remove(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.DELETE_BUSINESSSCENARIO:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessScenarioAccessService().remove(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.DELETE_BUSINESSUSECASE:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessUsecaseAccessService().remove(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.DELETE_BUSINESSFUNCTION:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessFunctionAccessService().remove(request.spec[0], onOperationReturn, request);
                 break;
              case ItestOperationEvent.UPDATE_BUSINESSREPOSITORY:
                 ServiceManagerComObasTestingFlexRemoting.getBusinessRepositoryAccessService().update(request.spec[0], onOperationReturn, request);
                 break;
              default:
                 break;
           }
       }

       [RequestHandler("{com.obas.event.TestPlanOperationEvent.REQUEST_ID}")]
       public static function onTestPlanOperationEvent(request:TestPlanOperationEvent):void {
          switch (request.actionType) {
             case TestPlanOperationEvent.GET_TEST_PLAN:
                ServiceManagerComObasTestingFlexRemoting.getTestPlanAccessService().findAll(null, onOperationReturn, request);
                break;
             case TestPlanOperationEvent.CREATE_TEST_PLAN:
                ServiceManagerComObasTestingFlexRemoting.getTaskExecutionManagementService().createTestPlan(request.spec[0], onOperationReturn, request);
                break;
             case TestPlanOperationEvent.GET_TASK:
                ServiceManagerComObasTestingFlexRemoting.getTestTaskAccessService().findByTestPlanId(request.spec[0], onOperationReturn, request);
                break;
             case TestPlanOperationEvent.GET_TASK_ITEM:
                ServiceManagerComObasTestingFlexRemoting.getTestTaskItemAccessService().findByTestTaskId(request.spec[0], onOperationReturn, request);
                break;
             case TestPlanOperationEvent.GET_SYS_FUN:
                ServiceManagerComObasTestingFlexRemoting.getTaskExecutionManagementService().listSystemFunctionObject(onOperationReturn, request);
                break;
             case TestPlanOperationEvent.RUN_TEST_PLAN:
                ServiceManagerComObasTestingFlexRemoting.getTaskExecutionManagementService().runTestPlan(request.spec[0], request.spec[1], onOperationReturn, request);
                break;
             case TestPlanOperationEvent.GET_PLAN_REPORT:
                ServiceManagerComObasTestingFlexRemoting.getTestPlanAccessService().getTestResultById(request.spec[0], onOperationReturn, request);
                break;
             default:
                break;
          }
       }

       [RequestHandler("{com.obas.event.ScriptOperationEvent.REQUEST_ID}")]
       public static function onScriptOperationEvent(request:ScriptOperationEvent):void {
          switch (request.actionType) {
//             case ScriptOperationEvent.START_APP:
//                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().startAut(request.spec[0], request.spec[1], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.START_RECORD:
//                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().beginRecord(request.spec[0], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.END_RECORD:
//                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().endRecord(request.spec[0], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.START_RUN:
//                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().startPlay(request.spec[0], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.GET_PROPERTIES:
//                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().getProperties(request.spec[0], request.spec[1], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.GET_TREE_ROOT:
//                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().getTreeRoot(request.spec[0], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.GET_TREE_CHILDREN:
//                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().getTreeChildren(request.spec[0], request.spec[1], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.TOGGLE_INSPECT_FRAME:
//                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().toggleInspectFrame(request.spec[0], request.spec[1], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.TOGGLE_INSPECT_MODE:
//                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().toggleInspectMode(request.spec[0], request.spec[1], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.CREATE_VERIFY_CODE:
////                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().toggleInspectMode(request.spec[0], request.spec[1], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.SAVE_TEST_SCRIPT:
//                ServiceManagerComObasTestingFlexRemoting.getParameterizedScriptManagementService().saveScript(request.spec[0], request.spec[1], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.FETCH_TEST_SCRIPT:
//                ServiceManagerComObasTestingFlexRemoting.getTestcaseScriptAccessService().findById(request.spec[0], onOperationReturn, request);
//                break;
//             case ScriptOperationEvent.STOP_APP:
//                ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().shutDownAut(request.spec[0], onOperationReturn, request);
//                break;
          }
       }

      [RequestHandler("{com.obas.event.RequestExplorerEvent.REQUEST_ID}")]
      public static function onRequestExplorerEvent(request:RequestExplorerEvent):void {
         switch (request.actionType) {
            case RequestExplorerEvent.TYPE_GET_ROOT:
               ServiceManagerComObasTestingFlexRemoting.getExplorerManagementService().findProjectExplorer(onOperationReturn, request);
               break;
            case RequestExplorerEvent.TYPE_GET_CHILDREN_EXP:
               ServiceManagerComObasTestingFlexRemoting.getExplorerManagementService().findChildExplorer(onOperationReturn, request);
               break;
            case RequestExplorerEvent.TYPE_GET_CHILDREN_ENTITY:
               ServiceManagerComObasTestingFlexRemoting.getExplorerManagementService().findChildEntity(onOperationReturn, request);
               break;
            case RequestExplorerEvent.TYPE_GET_ACTION:
               break;
            default:
               break;
         }
      }


      [RequestHandler("{com.obas.event.ParameterPoolEvent.REQUEST_ID}")]
      public static function onParameterPoolEvent(request:ParameterPoolEvent):void {
         switch (request.actionType) {
            case ParameterPoolEvent.TYPE_findByTestcaseScriptId:
               ServiceManagerComObasTestingFlexRemoting.getParameterPoolManagementService().findByTestcaseScriptId(request.testcaseScriptId, onOperationReturn, request);
         break;
      case ParameterPoolEvent.TYPE_save:
        ServiceManagerComObasTestingFlexRemoting.getParameterPoolManagementService().save(request.parameterPoolListObject, onOperationReturn, request);
               //				  break;
               //			  case ParameterPoolEvent.START_RECORD:
               //				  ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().beginRecord(request.spec[0], onOperationReturn, request);
               //				  break;
               //			  case ParameterPoolEvent.END_RECORD:
               //				  ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().endRecord(request.spec[0], onOperationReturn, request);
               //				  break;
               //			  case ParameterPoolEvent.START_RUN:
               //				  ServiceManagerComObasTestingFlexRemoting.getITestMonitorService().startPlay(request.spec[0], onOperationReturn, request);
               break;
         }
      }

      private static function onOperationReturn(event:MethodReturnEvent):void {
         ServiceManagerComObasTestingFlexRemoting.onOperationReturn(getInstance(), event);
      }

      private static var _instance:TestingLibCommand = null;

      private static function getInstance():TestingLibCommand {
         if (_instance == null) {
            _instance = new TestingLibCommand();
            ViewRegistry.instance.eventBus.addParticipant(_instance, true);
         }

         return _instance;
      }
   }
}